package com.scrumtrek.trainings.tdd;

import com.scrumtrek.trainings.tdd.model.Book;
import com.scrumtrek.trainings.tdd.model.IStore;
import com.scrumtrek.trainings.tdd.model.Item;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: Vadim
 * Date: 12.09.13
 * Time: 11:13
 * To change this template use File | Settings | File Templates.
 */
public class StubStore<T extends Item> implements IStore<T> {
    private IPaySystem paySystem = new IPaySystem() {
        public void increaseProfit(int cash) {
        }
    };

    private Set<T> items = new HashSet<T>();

    public final Collection<T> getItems() {
        return Collections.unmodifiableCollection(items);
    }

    public final void addItem(T item) {
        items.add(item);
    }

    public final void sellItem(T item) {
        if (removeItem(item)) {
            paySystem.increaseProfit(item.getPrice());
        }
    }

    public final boolean removeItem(T item) {
        return items.remove(item);
    }

    public final int getItemsCount() {
        return items.size();
    }
}
